<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
<script src="../calendar-picker/resources/calendar-picker-common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<input type="date" id="date">

<script>
description('Test for child elements of a datalist element.');

openPicker(document.getElementById('date'), test);

function makeRect(x, y, width, height) {
    return {
        x: x,
        y: y,
        width: width,
        height: height
    };
}

function test() {
    Object.defineProperty(popupWindow, 'screen', {
        value: {
            width: 80,
            height: 60,
            availLeft: 0,
            availTop: 0,
            availWidth: 80,
            availHeight: 60
        }
    });

    debug("Move anchor element along the vertical axis.");

    popupWindow.global.params.anchorRectInScreen = makeRect(0, -20, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,-10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, -10, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,0,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 10, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,20,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 20, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,30,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 30, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,40,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 40, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,50,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 50, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,40,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 60, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,50,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 70, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,60,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 80, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,70,30,10)');

    debug("Move anchor element along the horizontal axis.");

    popupWindow.global.params.anchorRectInScreen = makeRect(-40, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(-40,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(-30, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(-30,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(-20, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(-20,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(-10, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(-10,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(0,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(10, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(10,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(20, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(20,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(30,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(40, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(40,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(50, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(50,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(60, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(50,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(70, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(60,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(80, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(70,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(90, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(80,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(100, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(90,10,30,10)');

    debug("Move anchor element along the vertical axis. Open popup that is too tall.");

    popupWindow.global.params.anchorRectInScreen = makeRect(0, -20, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,-10,30,60)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, -10, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,0,30,60)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,10,30,50)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 10, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,20,30,40)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 20, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,30,30,30)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 30, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,0,30,30)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 40, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,0,30,40)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 50, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,0,30,50)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 60, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,0,30,60)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 70, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,10,30,60)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 80, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 10).toString()', 'Rectangle(0,20,30,60)');

    debug("Move anchor element along the vertical axis. Open popup that is too tall and won't shrink.");

    popupWindow.global.params.anchorRectInScreen = makeRect(0, -20, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-10,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, -10, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,0,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 0, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,10,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 10, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,20,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 20, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,30,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 30, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-970,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 40, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-960,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 50, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-950,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 60, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-940,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 70, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-930,30,1000)');

    popupWindow.global.params.anchorRectInScreen = makeRect(0, 80, 20, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 1000, 30, 1000).toString()', 'Rectangle(0,-920,30,1000)');

    debug("Grow popup width.");

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(30, 10, 30, 10).toString()', 'Rectangle(30,10,30,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(40, 10, 40, 10).toString()', 'Rectangle(30,10,40,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(50, 10, 50, 10).toString()', 'Rectangle(30,10,50,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(60, 10, 60, 10).toString()', 'Rectangle(0,10,60,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(70, 10, 70, 10).toString()', 'Rectangle(30,10,70,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(80, 10, 80, 10).toString()', 'Rectangle(30,10,80,10)');

    popupWindow.global.params.anchorRectInScreen = makeRect(30, 0, 30, 10);
    shouldBeEqualToString('popupWindow.adjustWindowRect(90, 10, 90, 10).toString()', 'Rectangle(30,10,90,10)');

    finishJSTest();
}

</script>
</body>
</html>
